<?php

namespace App\Http\Controllers\View\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Facades\Services\Admin\ArticleService;
use App\Facades\Utils\ValidateParameter;

class ArticleController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('pages.admin.article.list',[
            'articles' => ArticleService::getArticles()
        ]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('pages.admin.article.create');
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request)
    {
        $rules = [
            'id' => 'required|exists:articles,id'
        ];

        ValidateParameter::validate($request,$rules);

        $data = $request->all();

        return view('pages.admin.article.update',[
            'article' => ArticleService::getArticle($data)
        ]);
    }
}
